home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mmdf / mmdf-IIb.43 / src / niftp / qu2pn_send.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-02-01  |  7.5 KB  |  301 lines

  1. #include "util.h"
  2. #include "mmdf.h"
  3.  
  4. /*
  5.  *     MULTI-CHANNEL MEMO DISTRIBUTION FACILITY  (MMDF)
  6.  *
  7.  *
  8.  *     Copyright (C) 1979,1980,1981  University of Delaware
  9.  *
  10.  *     Department of Electrical Engineering
  11.  *     University of Delaware
  12.  *     Newark, Delaware  19711
  13.  *
  14.  *     Phone:  (302) 738-1163
  15.  *
  16.  *
  17.  *     This program module was developed as part of the University
  18.  *     of Delaware's Multi-Channel Memo Distribution Facility (MMDF).
  19.  *
  20.  *     Acquisition, use, and distribution of this module and its listings
  21.  *     are subject restricted to the terms of a license agreement.
  22.  *     Documents describing systems using this module must cite its source.
  23.  *
  24.  *     The above statements must be retained with all copies of this
  25.  *     program and may not be removed without the consent of the
  26.  *     University of Delaware.
  27.  *
  28.  *
  29.  *     version  -1    David H. Crocker    March   1979
  30.  *     version   0    David H. Crocker    April   1980
  31.  *     version  v7    David H. Crocker    May     1981
  32.  *     version   1    David H. Crocker    October 1981
  33.  *
  34.  */
  35. /*                  SEND FROM DELIVER TO NIFTP CHANNEL
  36.  *
  37.  *      Adapted by Steve Kille from module to communicate with local channel
  38.  *      July 1982
  39.  *
  40.  *      Mar 82  Steve Kille    Modify to use new MMDF - in particular the new
  41.  *                                sub-list structuring
  42.  *
  43.  */
  44.  
  45. #include "ch.h"
  46. #include "phs.h"
  47. #include "ap.h"
  48.  
  49. extern struct ll_struct   *logptr;
  50. extern char *qu_msgfile;          /* name of file containing msg text   */
  51. extern Chan *chanptr;
  52.  
  53. LOCVAR int nadrs;               /* to keep a count of the addresses     */
  54.  
  55. LOCVAR struct rp_construct
  56.                 rp_adr  =
  57. {
  58.     RP_AOK, 'a', 'd', 'd', 'r', 'e', 's', 's', ' ', 'o', 'k', '\0'
  59. },
  60.  
  61.                 rp_hend     =
  62. {
  63.     RP_MOK, 'P', ' ', 'N', 'i', 'f', 't', 'p', ' ', 'e', 'n', 'd', ' ',
  64.      'o', 'f', ' ', 'a',  'd', 'd', 'r', ' ', 'l', 'i', 's', 't', '\0'
  65. };
  66.  
  67. LOCVAR struct rp_construct
  68.                 rp_temp     =
  69. {
  70.     RP_LIO, 'P', ' ', 'N', 'i', 'f', 't', 'p', ',', ' ', 't', 'e', 'm',
  71.      'p', ' ', 'f', 'a', 'i', 'l', 'u', 'r', 'e', '\0'
  72. };
  73.  
  74. LOCVAR struct rp_construct
  75.                 rp_perm     =
  76. {
  77.     RP_NDEL, 'P', ' ', 'N', 'i', 'f', 't', 'p', ' ',
  78.     'p', 'e', 'r', 'm', 'a', 'n', 'a', 'n', 't', ' ',
  79.     'f', 'a', 'i', 'l', 'u', 'r', 'e', '\0'
  80. };
  81.  
  82. LOCVAR struct rp_construct
  83.                 rp_bhst     =
  84. {
  85.     RP_BHST, 'B', 'a', 'd', ' ', 'H', 'o', 's', 't', '\0'
  86. };
  87.  
  88.  
  89. LOCVAR struct rp_construct
  90.                rp_noadr     =
  91. {
  92.     RP_NDEL, 'N', 'o', ' ', 'v', 'a', 'l', 'i', 'd', ' ', 'a', 'd', 'd',
  93.     'r', 'e', 's', 's', 's', 'e', 's', '\0'
  94. };
  95.  
  96. LOCVAR struct rp_construct
  97.               rp_noop       =
  98. {
  99.     RP_NOOP, 'E', 'n', 'd', ' ', 'o', 'f', ' ', 'h', 'o', 's', 't', ' ',
  100.     'i', 'g', 'n', 'o', 'r', 'e', 'd', '\0'
  101. };
  102.  
  103. /* */
  104.  
  105. qu2pn_send (chname)                /* overall mngmt for batch of msgs    */
  106. char    chname [];
  107. {
  108.     short     result;
  109.     char    info[LINESIZE],
  110.         sender[LINESIZE];
  111.  
  112. #ifdef DEBUG
  113.     ll_log (logptr, LLOGBTR, "qu2pn_send ()");
  114. #endif
  115.  
  116.     if (rp_isbad (result = qu_pkinit ()))
  117.     return (result);
  118.  
  119.     if (rp_isbad (result = pn_sbinit ()))
  120.     {
  121.     printx ("problem with niftp submission... ");
  122.     return (result);
  123.     }
  124.  
  125.     for(;;){                /* get initial info for new message   */
  126.     result = qu_rinit (info, sender, chanptr -> ch_apout);
  127.     if(rp_gval(result) == RP_NS){
  128.         qu_rend();
  129.         continue;
  130.     }
  131.     else if(rp_gval(result) != RP_OK)
  132.         break;
  133.     if (rp_isbad (result =
  134.             pn_winit (chname, sender, qu_msgfile)))
  135.         return (result);      /* ready to write message out         */
  136.  
  137.     if (rp_isbad (result = qu2pn_each ()))
  138.                 /* Now process the addresses and text   */
  139.                 /* for this message                     */
  140.         return (result);
  141.     qu_rend();
  142.     }
  143.     qu_rend();
  144.  
  145.     if (rp_gval (result) != RP_DONE)
  146.     {
  147.     ll_log (logptr, LLOGTMP, "not DONE (%s)", rp_valstr (result));
  148.     return (RP_RPLY);         /* catch protocol errors              */
  149.     }
  150.  
  151.     qu_pkend ();                  /* done getting messages              */
  152.     if (rp_isbad (result = pn_sbend ()))
  153.                   /* done sending messages              */
  154.     {
  155.     printx ("bad ending for NIFTP delivery... ");
  156.     fflush (stdout);
  157.     }
  158.  
  159.     return (result);
  160. }
  161. /* */
  162.  
  163.  
  164. LOCFUN
  165.     qu2pn_each ()             /* send copy of text per address      */
  166. {
  167.     short     result;
  168.     short     txt_result;
  169.     char    host[LINESIZE];
  170.     char    adr[LINESIZE];
  171.  
  172. #ifdef DEBUG
  173.     ll_log (logptr, LLOGBTR, "qu2sm_each()");
  174. #endif
  175.  
  176.     phs_note (chanptr, PHS_WRSTRT);
  177.  
  178.     nadrs = 0;
  179.     if (rp_isbad (result = pn_wainit()))
  180.     return (result);
  181.  
  182.     FOREVER                     /* iterate thru list                    */
  183.     {
  184.     result = qu_radr (host, adr);
  185.     if (rp_isbad (result))
  186.         return (result);      /* get address from Deliver           */
  187.  
  188. /*  check for end of address sub-list.  different
  189.  *  sub-lists reference different hosts to connect to.
  190.  */
  191.     switch (rp_gval (result))
  192.     {
  193.         case RP_HOK:          /* end of sub-list */
  194.         if (chanptr -> ch_host != NORELAY)
  195.         {
  196.                 /* send all addresses to relay at once */
  197.             qu_wrply ((struct rp_bufstruct *) &rp_noop,
  198.                         rp_conlen (rp_noop));
  199.             continue;
  200.         }
  201.         case RP_DONE:         /* end of list so fire it off */
  202. #ifdef DEBUG
  203.     ll_log (logptr, LLOGFTR, "End of list or sublist (%s)",
  204.             rp_valstr (result));
  205. #endif
  206.  
  207.         if (nadrs == 0)
  208.         {
  209.             pn_wtend (RP_NO);  /* terminate current message    */
  210.             qu_wrply ((struct rp_bufstruct *) &rp_noadr,
  211.                 sizeof rp_noadr);
  212.                     /* assume strange temp error    */
  213.         }
  214.         else
  215.         {
  216.             nadrs = 0;      /* reset, in case this is only a hend */
  217.             if (rp_isbad (txt_result = qu2pn_txtcpy ()))
  218.             {
  219.                     /* Tell other side of problem    */
  220.             if (rp_gbval (txt_result) == RP_BTNO)
  221.                     /*  temp error                  */
  222.                 qu_wrply ((struct rp_bufstruct *) &rp_temp,
  223.                 rp_conlen (rp_temp));
  224.             else
  225.                 qu_wrply ((struct rp_bufstruct *) &rp_perm,
  226.                 rp_conlen (rp_perm));
  227.                     /* no reason to abort though    */
  228.             }
  229.             else
  230.             qu_wrply ((struct rp_bufstruct *) &rp_hend,
  231.                 rp_conlen (rp_hend));
  232.         }
  233.         if (rp_gval (result) == RP_DONE)
  234.             return (RP_OK);
  235.                 /* end of list - so return          */
  236.                 /* otherwise sort prepare for another one */
  237.         if (rp_isbad (result = pn_wainit ()))
  238.             return (result);
  239.         continue;
  240.  
  241.         default:            /* actually have an address */
  242.         if (rp_isbad (result = pn_wadr (host, adr)))
  243.         {
  244.             pn_wtend (result);  /* clean up and get out         */
  245.             return (result);
  246.         }
  247.  
  248.         nadrs++;
  249.  
  250.         qu_wrply ((struct rp_bufstruct *) &rp_adr, rp_conlen (rp_adr));
  251.         continue;
  252.     }
  253.     }
  254.     /* NOTREACHED */
  255. }
  256.  
  257. /* */
  258.  
  259. LOCFUN
  260.     qu2pn_txtcpy ()             /* copy the text of the message       */
  261. {
  262.     short   result;
  263.     int     len;
  264.     char    buffer[BUFSIZ];
  265.  
  266. #ifdef DEBUG
  267.     ll_log (logptr, LLOGBTR, "qu2pn_txtcpy()");
  268. #endif
  269.  
  270.     phs_note (chanptr, PHS_WRMSG);
  271.  
  272.     if (rp_isbad (result = pn_wtinit ()))
  273.     return (result);
  274.  
  275.     qu_rtinit (0L);              /* ready to read the text             */
  276.     len = sizeof(buffer);
  277.     while ((rp_gval (result = qu_rtxt (buffer, &len))) == RP_OK)
  278.     {                             /* send the text                      */
  279.     if (rp_isbad (result = pn_wtxt (buffer, len)))
  280.         break;
  281.     if (rp_gval (result) != RP_OK)
  282.     {
  283.         result = RP_RPLY;
  284.         break;
  285.     }
  286.     len = sizeof(buffer);
  287.     }
  288.  
  289.  
  290.     if (rp_isgood (result) && rp_gval (result) != RP_DONE)
  291.     result = RP_RPLY;        /* didn't get it all across?          */
  292.  
  293.     if (rp_isbad (result = pn_wtend (result)))
  294.     return (result);          /* flag end of message                */
  295.                   /* and then it can be sent off        */
  296.  
  297.     phs_note (chanptr, PHS_WREND);
  298.  
  299.     return (RP_MOK);               /* got the text out                   */
  300. }
  301.